using System;
using System.Collections.Generic;
using System.Text;

namespace RapidHDL
{
    public class CompareGreaterEqual : Component
    {
        public NodeVector InputNodesA;
        public NodeVector InputNodesB;
        public NodeVector Output;

        public CompareGreaterEqual(Component poParentComponent, string psName, int piWidthA, int piWidthB)
            : base(poParentComponent, psName)
        {
            InputNodesA = this.CreateNodeVector("InA", piWidthA);
            InputNodesB = this.CreateNodeVector("InB", piWidthB);
            Output = this.CreateNodeVector("Out", 1);
        }

        public override void GenerateStructure()
        {
            NodeVector nvExtraBits = null;
            int iWidth = InputNodesA.Width;
            if (iWidth < InputNodesB.Width)
            {
                iWidth = InputNodesB.Width;
            }

            Adder oAdder = new Adder(this, "subtract", iWidth, iWidth, true);
            oAdder.Carry.Join(1);
            oAdder.InputNodesA.Join(InputNodesA);
            oAdder.InputNodesB.Join(!InputNodesB);
            Output.Join(oAdder.OutputNodes[iWidth, iWidth]);
            Utility.SinkExtraBits(this, oAdder.OutputNodes[0, iWidth - 1]);
            if (InputNodesA.Width < InputNodesB.Width)
            {
                InputNodesB[InputNodesA.Width, InputNodesB.Width - 1].Join(0);
            }
            if (InputNodesB.Width < InputNodesA.Width)
            {
                InputNodesA[InputNodesB.Width, InputNodesA.Width - 1].Join(0);
            }
        }

        /*public override string GenerateVerilog()
        {
            ComponentVerilog.Write
        }

        public override void CalculateOutput()
        {
            string sA = InputNodesA.NodeVectorAsString;
            string sB = InputNodesB.NodeVectorAsString;
            if (sA.Length > sB.Length)
            {
                sB.PadLeft(sA.Length - sB.Length, '0');
            }
            if (sB.Length > sA.Length)
            {
                sA.PadLeft(sB.Length - sA.Length, '0');
            }

            if (sA == sB)
                Output.NodeVectorAsString = "1";
            else
                Output.NodeVectorAsString = "0";
        }*/

    }
}
